package com.ljh.blog.controller;

import com.ljh.blog.pojo.dataobject.UserInfo;
import com.ljh.blog.pojo.request.UserInfoRequest;
import com.ljh.blog.pojo.response.UserInfoResponse;
import com.ljh.blog.pojo.response.UserLoginResponse;
import com.ljh.blog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Themberfue
 * @date: 2025/3/30 20:50
 * @description:
 */
@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Resource(name = "userServiceImpl")
    UserService userService;

    @PostMapping("/login")
    public UserLoginResponse login(@RequestBody @Validated UserInfoRequest userInfo) {
        System.out.println(userInfo);
        log.info("用户登录：username：{}", userInfo.getUserName());
        return userService.login(userInfo);
    }

    @GetMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull(message = "用户id不得为空") Integer userId) {
        log.info("获得用户信息：用户id：{}", userId);
        return userService.getUserInfo(userId);
    }

    @GetMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull(message = "博客id不得为空") Integer blogId) {
        log.info("获得作者信息：博客id：{}", blogId);
        return userService.getAuthorInfo(blogId);
    }
}
